﻿#ifndef IOSTATE_H
#define IOSTATE_H

#include "param.h"
#include <QBitArray>
#include <QComboBox>
#include <QDebug>
#include <QFile>
#include <QLabel>
#include <QMainWindow>
#include <QPushButton>
#include <QSettings>
#include <QSignalMapper>
#include <QVBoxLayout>

class IoStateUi : public QWidget {
    Q_OBJECT

public:
    explicit IoStateUi( QWidget* parent = nullptr );
    //   ~IoStateUi();

    void readIoDefineFile();
    void setIoType();
    void setIoName();

signals:
    void sigToggleDoBit( int module_id, int id );

public slots:
    void sltToggleDo( int id );
    void slotRecvIoData( const QBitArray& ioState );
    void sltSetIoType( const QBitArray& ioType );
    void sltChangeIoModule( int );

private:
    QVBoxLayout* total_layout_;  //整体layout, 包含combo box 和 io layout
    QHBoxLayout* io_layout_;     // 包含左右io
    QVBoxLayout* left_layout_;   // 把左边的16个联合起来的layout
    QVBoxLayout* right_layout_;  //把右边的16个联合起来的layout
    QHBoxLayout* item_layout_;   // label + button 的layout

    QList< QLabel* >      label_list_;  //储存所有的pic图标
    QList< QPushButton* > button_list_;
    QPixmap               off_pic_;
    QPixmap               on_pic_;
    QSignalMapper*        signal_mapper_ = nullptr;
    QStringList           io_name_list_;
    int                   cur_module_index_;
    int                   read_io_num;
    QBitArray             io_type_;
};

#endif  // IOSTATE_H
